package com.example.big_event.controller;


import com.example.big_event.pojo.Article;
import com.example.big_event.pojo.PageBean;
import com.example.big_event.pojo.Result;
import com.example.big_event.service.ArticleService;
import com.example.big_event.utils.ThreadLocalUtil;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/article")
public class ArticleController {

    @Autowired//注解注入service
    ArticleService service;

    @PostMapping//添加文章方法  传入文章实体类
    public Result<String> display(@RequestBody @Validated Article article){

        //service调方法 返回信息
        service.add(article);
        return Result.success();
    }

    @GetMapping//文章分页显示  需要借助pagehelper插件  传入页码和每页显示条数 文章id、状态设置为不必要传入
    public Result<PageBean<Article>> list(Integer PageNum,Integer PageSize,@RequestParam(required = false)Integer categoryId
            ,@RequestParam(required = false)String state ){


        //serv调用方法  返回信息
        PageBean<Article> pb = service.list(PageNum,PageSize,categoryId,state);

        return Result.success(pb);


    }

}
